﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Coolite.Ext.Web;

public partial class WebControl_wucContas : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Ext.IsAjaxRequest)
        {
            strGridConta_RefreshData(null, null);
        }
    }
    protected void strGridConta_RefreshData(object sender, StoreRefreshDataEventArgs e)
    {
        bllContas _Contas = new bllContas();
        strGridConta.DataSource = _Contas.GetDados(0, clGlobal.GetIdAplGroup());
        strGridConta.DataBind();
    }
    protected void EditarContaClick(object sender, AjaxEventArgs e)
    {
        RowSelectionModel sm = this.GridCadConta.SelectionModel.Primary as RowSelectionModel;
        bllContas _Contas = new bllContas(Convert.ToInt32(sm.SelectedRow.RecordID));
        txt_Id_Conta.Text = _Contas.objContas.Cta_Id_Conta.ToString();
        txt_NomeConta.Text = _Contas.objContas.Cta_tx_NomeConta;
        cbxTipoConta.SelectedItem.Value = _Contas.objContas.Cta_tx_TipoConta;
        txtCodBanco.Text = _Contas.objContas.Cta_tx_CodBanco;
        txtCodAgencia.Text = _Contas.objContas.Cta_tx_CodAgencia;
        txtNumConta.Text = _Contas.objContas.Cta_tx_NumeroConta;
        wdwDadosConta.Show();
    }
    protected void NovoContaClick(object sender, AjaxEventArgs e)
    {
        txt_Id_Conta.Text = "";
        txt_NomeConta.Text = "";
        cbxTipoConta.SelectedItem.Value = "C";
        txtCodBanco.Text = "";
        txtCodAgencia.Text = "";
        txtNumConta.Text = "";
        wdwDadosConta.Show();
    }
    protected void SalvarContaClick(object sender, AjaxEventArgs e)
    {
        bllContas _Contas = new bllContas();
        _Contas.objContas.Cta_Id_Conta = string.IsNullOrEmpty(txt_Id_Conta.Text) ? 0 : Convert.ToInt32(txt_Id_Conta.Text);
        _Contas.objContas.Cta_tx_NomeConta = txt_NomeConta.Text.ToUpper();
        _Contas.objContas.Cta_tx_TipoConta = cbxTipoConta.SelectedItem.Value.ToString();
        _Contas.objContas.Cta_tx_CodBanco = string.IsNullOrEmpty(txtCodBanco.Text) ? null : txtCodBanco.Text.ToUpper();
        _Contas.objContas.Cta_tx_CodAgencia = string.IsNullOrEmpty(txtCodAgencia.Text) ? null : txtCodAgencia.Text.ToUpper();
        _Contas.objContas.Cta_tx_NumeroConta = string.IsNullOrEmpty(txtNumConta.Text) ? null : txtNumConta.Text.ToUpper();
        _Contas.objContas.Agr_Id_AplGroup = clGlobal.GetIdAplGroup();
        txt_Id_Conta.Text = _Contas.SetContas().ToString();
    }
    protected void DeletarContaClick(object sender, AjaxEventArgs e)
    {
        RowSelectionModel sm = this.GridCadConta.SelectionModel.Primary as RowSelectionModel;
        bllCartao _Contas = new bllCartao();
        _Contas.DelCartao(Convert.ToInt32(sm.SelectedRow.RecordID));
        //
        sm.SelectedRows.Clear();
        sm.UpdateSelection();
    }
}
